package Poker;

//买一副牌 52张牌 4个花色
//洗牌
//接牌


import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ADeckOfCards {
    public static final String[] SUITS = {"♥", "♣", "♦", "♠"};//定义花色

    //买一副扑克牌
    public static List<Poker> buyPoker() {
        List<Poker> pokerList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j <= 13; j++) {
                String suit = SUITS[i];
                //int rank=j;
                Poker poker = new Poker(suit, j);
                pokerList.add(poker);
            }
        }
        return pokerList;
    }

    //洗牌
    public static void swap(List<Poker> pokerList, int i, int j) {
        Poker tmp = pokerList.get(i);
        pokerList.set(i, pokerList.get(j));//更新下标值
        pokerList.set(j, tmp);
    }

    public static void shuffle(List<Poker> pokerList) {
        Random random = new Random();
        for (int i = pokerList.size() - 1; i > 0; i--) {
            int r = random.nextInt(i);
            swap(pokerList,i,r);
        }
    }


    public static void main(String[] args) {
        List<Poker> pokerList = buyPoker();
        System.out.println("买牌：" + pokerList);
        shuffle(pokerList);
        System.out.println("洗牌：" + pokerList);

        //接牌 3人 每人轮流抓五张
        //1.如何描述三个人
        List<Poker>hand1=new ArrayList<>();
        List<Poker>hand2=new ArrayList<>();
        List<Poker>hand3=new ArrayList<>();
        //2.如何区分往哪个人手里放牌
        List<List<Poker>>hand=new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                List<Poker>handTmp=hand.get(j);//确定是谁的手
               handTmp.add(pokerList.remove(0)) ;//摸走的过程就是删除的过程
            }
        }
        for (int i = 0; i < hand.size(); i++) {
            System.out.println("第"+i+"个人的牌是："+hand.get(i));
        }
        System.out.println(pokerList);
    }
}


